package cn.main.entity.sys;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Set;

/**
 * Author: chengwei
 * Date:   2016/7/12
 * Time:   16:50
 */
@Entity
@Table(name = "sys_authority")
public class Authority implements Serializable {
    private static final long serialVersionUID = 4724167656139907571L;
    @Id
    @Column(name = "authority_id")
    private String authorityId;
    @Column(name = "function_id")
    private String functionId;
    @Column(name = "name")
    private String name;
    
    @ManyToMany(mappedBy = "authorities")
    private Set<Role> roles;

    public String getAuthorityId() {
        return authorityId;
    }

    public void setAuthorityId(String authorityId) {
        this.authorityId = authorityId;
    }

    public String getFunctionId() {
        return functionId;
    }

    public void setFunctionId(String functionId) {
        this.functionId = functionId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Authority authority = (Authority) o;

        return !(getAuthorityId() != null ? !getAuthorityId().equals(authority.getAuthorityId()) : authority.getAuthorityId() != null);

    }

    @Override
    public int hashCode() {
        return getAuthorityId() != null ? getAuthorityId().hashCode() : 0;
    }
}
